<?PHP
	class Application extends Controller {
		var $view;
		function Application(){
			parent::Controller($this);
		}
		function onError($level,$message,$file,$line){
			switch($level){
				default:
				case 0:
					Logger::log("Error",$message);
					//." [$file line $line]");
					break;
				case 1:
					Logger::log("Warning",$message);
					//." [$file line $line]");
					break;
				case 2:
					Logger::log("Notice",$message);
					//." [$file line $line]");
					break;
			}
		}
		function onAppStart($class,$method,$params){
			if(APP_USE_SESSIONS){
				import('persistence.Session');
				Session::start();
			}
			if(APP_USE_TEMPLATES){
				import('view.View');
				$this->view = new View(APP_VIEWS_LOCATION.APP_BASE_TEMPLATE);
			}
		}
		function getCredentials($access_level){
			return TRUE;
		}
		function onAppExit($render=TRUE){
			if($render!==FALSE){
				if(APP_USE_TEMPLATES){
					if(APP_DEBUG_MODE){
						$debugContent = (Config::exists("APP_DEBUG_TEMPLATE")) ? View::load(APP_DEBUG_TEMPLATE,array("debug"=>Logger::render())) : "<div class=\"debug\">".Logger::render()."</div>" ;
						$this->view->set("debug",$debugContent);
					}
					$result = $this->view->render();
					echo $result;
				}else{
					if(APP_DEBUG_MODE) echo "<div class=\"debug\">".Logger::render()."</div>";
				}
			}else{
				if(APP_DEBUG_MODE) echo "<div class=\"debug\">".Logger::render()."</div>";
			}
		}
		
	}
?>